# -*- coding:utf-8 -*-
"""
元素查找类

    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"
"""
from selenium.webdriver.common.by import By

class Element:
    def __init__(self, driver):
        self.driver = driver

    def id(self, idStr):
        """
        driver.find_element(By.ID, "name")
        :param idStr:
        :return:
        """
        return self.driver.find_element(By.ID, value=idStr)

    def class_name(self, classNameStr):
        """
        find_element(By.CLASS_NAME, "information")
        :param classNameStr:
        :return:
        """
        return self.driver.find_element(By.CLASS_NAME, value=classNameStr)

    def css(self, cssSelectorStr):
        """
        driver.find_element(By.CSS_SELECTOR, '[name="q"]')
        driver.find_element(By.CSS_SELECTOR,"#fruits .tomatoes")
        driver.find_element(By.CSS_SELECTOR, "#fname")
        :param cssSelectorStr:
        :return:
        """
        return self.driver.find_element(By.CSS_SELECTOR, value=cssSelectorStr)

    def name(self, nameStr):
        """
        driver.find_element(By.NAME, "newsletter")
        :param nameStr:
        :return:
        """
        return self.driver.find_element(By.NAME, value=nameStr)

    def tag_name(self, tagNameStr):
        """
        driver.find_element(By.TAG_NAME, "a")
        :param tagNameStr:
        :return:
        """
        return self.driver.find_element(By.TAG_NAME, value=tagNameStr)

    def xpath(self, xpathStr):
        """
        driver.find_element(By.XPATH, "//input[@value='f']")
        :param xpathStr:
        :return:
        """
        return self.driver.find_element(By.XPATH, value=xpathStr)

    def linkText(self, linkTextStr):
        """
        driver.find_element(By.LINK_TEXT, "Selenium Official Page")
        :param linkTextStr:
        :return:
        """
        return self.driver.find_element(By.LINK_TEXT, value=linkTextStr)

    def partial_link_text(self, partialLinkTextStr):
        """
        driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page")
        :param partialLinkTextStr:
        :return:
        """
        return self.driver.find_element(By.PARTIAL_LINK_TEXT, value=partialLinkTextStr)
